package cn.sxt.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Mxb
 * @version 1.0
 * @date 2020/4/29 10:45
 */
@Configuration
public class GatewayConfig {
    //配置一个id为route-name的路由规则
    //当访问 http://localhost:9527/guonei 时，会自动转发到 http://news.baidu.com/guonei
    @Bean
    public RouteLocator customeRouteLocater(RouteLocatorBuilder routeLocatorBuilder){
        RouteLocatorBuilder.Builder routes = routeLocatorBuilder.routes();
        routes.route("path_route_payment",
                r -> r.path("/guonei")
                        .uri("http://news.baidu.com/guonei")).build();
        return routes.build();
    }
}
